package com.jiuyi.controller;

import com.jiuyi.common.R;
import com.jiuyi.dto.AdminSetmealDto;
import com.jiuyi.entity.Setmeal;
import com.jiuyi.service.Impl.SetmealServiceImpl;
import com.jiuyi.vo.AdminSelectSetmealVo;
import com.jiuyi.vo.AdminUpdateSetmealVo;
import com.jiuyi.vo.SetMealListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * DATA: 2022/10/21
 * Author: 晨夕
 */
@RestController
@RequestMapping("/setmeal")
public class SetmealController {

    @Autowired
    private SetmealServiceImpl setmealServiceImpl;

    /**
     * 添加套餐
     */
    @PostMapping
    public R addSetmeal(@RequestBody AdminSetmealDto adminSetmealDto){
        return setmealServiceImpl.addSetmeal(adminSetmealDto);
    }
    /**
     * 分页查询套餐
     */
    @GetMapping("/page")
    public R<AdminSelectSetmealVo> selectSetmealList(int page, int pageSize, String name){
        return setmealServiceImpl.selectSetmealList(page, pageSize, name);
    }
    /**
     * 删除套餐
     */
    @DeleteMapping
    public R deleteSetmeal(Long[] ids){
        return setmealServiceImpl.deleteSetmeal(ids);
    }
    /**
     * 停售套餐
     */
    @PostMapping("/status/0")
    public R stopSetmeal(Long[] ids){
        return setmealServiceImpl.stopSetmeal(ids);
    }
    /**
     * 起售套餐
     */
    @PostMapping("/status/1")
    public R startSetmeal(Long[] ids){
        return setmealServiceImpl.startSetmeal(ids);
    }
    /**
     * 根据id查询套餐
     */
    @GetMapping("/{id}")
    public R<AdminUpdateSetmealVo> selectById(@PathVariable("id") Long id){
        return setmealServiceImpl.selectById(id);
    }
    /**
     * 修改套餐
     */
    @PutMapping
    public R updateSetmeal(@RequestBody AdminSetmealDto adminSetmealDto){
        return setmealServiceImpl.updateSetmeal(adminSetmealDto);
    }
    /**
     * 根据category_id查询套餐集合
     */
    @GetMapping("list")
    public R<SetMealListVo> selectListById(Long categoryId){
        return setmealServiceImpl.selectListById(categoryId);
    }
    /**
     * 根据id查询
     */
    @GetMapping("/dish/{id}")
    public R<Setmeal> selectDishById(@PathVariable("id") Long id){
        return setmealServiceImpl.selectDishById(id);
    }
}
